/*
 * PeakReference.cpp
 *
 *  Created on: Jan 6, 2011
 *      Author: blyth
 */

#include "PeakReference.h"

PeakReference::PeakReference(double const * const ref, unsigned int const size) :
	ref(ref), size(size + 2) {
	;
}

PeakReference::~PeakReference() {
	delete ref;
}

double PeakReference::cubicInterpolationAt(double xPos) {
	int x1 = (int) xPos + 1;
	xPos -= (int) xPos;

	double xPos2 = xPos * xPos;
	double a0 = .5 * ref[x1 + 2] - 1.5 * ref[x1 + 1] + 1.5 * ref[x1] - 0.5
			* ref[x1 - 1];
	double a1 = -0.5 * ref[x1 + 2] + 2 * ref[x1 + 1] - 2.5 * ref[x1] + ref[x1
			- 1];
	double a2 = 0.5 * ref[x1 + 1] - 0.5 * ref[x1 - 1];
	double a3 = ref[x1];

	return (a0 * xPos * xPos2 + a1 * xPos2 + a2 * xPos + a3);
}
